package com.lanxin.oa.personnel.dao;
import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.ZzAdjustment;
import com.lanxin.bean.ZzEmployee;
import com.lanxin.util.PageBean;
import org.springframework.stereotype.Repository;
import java.text.SimpleDateFormat;
import java.util.Date;

@Repository
public class AdjustDaoImpl extends BaseDaoImpl implements AdjustDao {
    @Override
    public ZzEmployee selectEmpById(Integer oid) {
        return (ZzEmployee) selectByHQL("from ZzEmployee z left join fetch z.dept left join fetch z.basic  where z.oid=" + oid);
    }

    @Override
    public ZzEmployee selectByIdAdjust(Integer oid) {
        return (ZzEmployee) selectByHQL("from ZzEmployee e left join fetch e.zzAdjustments where e.oid="+oid);
    }

    @Override
    public PageBean<ZzAdjustment> selectAdjustPage(Integer page, Integer pageSize, Integer empid, Date startDate, Date endDate) {
        SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
        if (page==null){
            page = 1;
        }
        if(pageSize == null){
            pageSize = 5;
        }
        String hql=("from ZzAdjustment z left join fetch z.emp left join fetch z.dept left join fetch z.department left join fetch z.basic left join fetch z.basicdatavalue where 1=1");
        if(empid!=null &&!"".equals(empid)){
            hql=hql+" and z.empid="+empid;
        }
        if(startDate!=null){

            hql=hql+" and z.adjustDate>='"+sim.format(startDate)+"'";
        }
        if(endDate!=null){
            hql=hql+" and z.adjustDate<='"+sim.format(endDate)+"'";
        }
        return super.pageFenYE(hql, page, pageSize);
    }
}
